<#import "/macro.ftl" as m>
<@m.page_header title='后台' />
<div id="page-content-wrapper">

    <div id="page-title">
        <h3>
            交易预警设置
        </h3>
        <div id="breadcrumb-right">
            <div class="float-right">
                <a href="javascript:;" class="btn medium primary-bg" onclick="showNewWarning();">
                    <span class="button-content">
                    <i class="glyph-icon icon-cog float-left"></i>
                    新增预警
                    </span>
                </a>
            </div>
        </div>
    </div>

    <div id="page-content">
        <table class="table" id="exp">
        </table>
    </div>
    
    <hr>
    
    <label for="">
                <font size="4">预警参数设置</font>
    </label>
    <br><br>
    <form id="demo-form2" action="/warning/save" class="col-md-12" method="POST">
    		<div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        订单失败预警：
                    </label>
                </div>
                <div class="form-input col-md-2">
                        <select name="orderSwitch">
			        		<option value="false" <#if parameter.orderSwitch == false>selected</#if>>关闭</option>
			        		<option value="true" <#if parameter.orderSwitch == true>selected</#if>>开启</option>
			        	</select>
                </div>
                <div class="form-label col-md-2">
                    <label for="">
                        失败条数：
                    </label>
                </div>
                <div class="form-input col-md-2">
                	<input type="text" id="orderFailNumber" name="orderFailNumber" data-type="number" data-trigger="change" data-required="true" class="parsley-validated" value="${parameter.orderFailNumber}">
            	</div>
            </div>
            
            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        银行支付预警：
                    </label>
                </div>
                <div class="form-input col-md-2">
                        <select name="bankSwitch">
			        		<option value="false" <#if parameter.bankSwitch == false>selected</#if>>关闭</option>
			        		<option value="true" <#if parameter.bankSwitch == true>selected</#if>>开启</option>
			        	</select>
                </div>
                <div class="form-label col-md-2">
                    <label for="">
                        失败条数：
                    </label>
                </div>
                <div class="form-input col-md-2">
                	<input type="text" id="bankFailNumber" name="bankFailNumber" data-type="number" data-trigger="change" data-required="true" class="parsley-validated" value="${parameter.bankFailNumber}">
            	</div>
            </div>
            
            <div class="form-row">
                <div class="form-label col-md-2">
                    <label for="">
                        排期预售预警：
                    </label>
                </div>
                <div class="form-input col-md-2">
                    <select name="presellSwitch">
		        		<option value="false" <#if parameter.presellSwitch == false>selected</#if>>关闭</option>
		        		<option value="true" <#if parameter.presellSwitch == true>selected</#if>>开启</option>
		        	</select>
                </div>
            </div>
            
            <div class="form-row">
		       <input type="hidden" name="superhidden" id="superhidden">
		       <div class="form-input col-md-10 col-md-offset-2">
		       		<a href="javascript:;" class="btn medium primary-bg radius-all-4 col-md-2" id="demo-form-2-valid">保存设置</a>
		       </div>
    		</div>
	</form>
	
    
</div>

<div id="dialog-add-presale" class="hide">
    <form id="demo-form1" action="/warning/add" method="post" class="mrg10A">
        <div class="row">
            <div class="col-md-6">
                <div class="form-row">
                    <div class="form-label col-md-6">
                        <label for="">预警负责人电话设置:</label>
                    </div>
                    <div class="form-input col-md-6">
                    	<input type="text" id="phoneNum" name="phoneNum" data-trigger="change" data-required="true" class="parsley-validated" value="">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-row">
                    <div class="form-label col-md-4">
                        <label for="">预警类型:</label>
                    </div>
                    <div class="form-input col-md-6">
                        <select name="warntype" aria-controls="exp">
                            <option value="AllDay" selected="selected">24小时预警</option>
                            <option value="NotAllDay">非24小时预警</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<script language="JavaScript">
    $(document).ready(function () {
    
    $("#demo-form-2-valid").click(function(){
			$('#demo-form2').parsley('validate');
	    	$('#demo-form2').trigger('submit');
	});
    
    <#if msg!=null>
	$.jGrowl("${msg}", {sticky:!1,position:'bottom-right',theme:'bg-green'});
	</#if>

        function retrieveData(sSource, aoData, fnCallback) {
            aoData.push({ });
            $.ajax({
                "type": "POST",
                "contentType": "application/json",
                "url": sSource,
                "dataType": "json",
                "data": JSON.stringify(aoData), //以json格式传递
                "success": fnCallback
            });
        }


        $(function () {
            $("#exp").dataTable({
                sScrollY: 300,
                bJQueryUI: !0,
                bStateSave: true,
                sPaginationType: "full_numbers",
                aoColumns: [
                    {'sTitle': 'id', 'mDataProp': 'id', "bVisible": false},
                    {'sTitle':'预警负责人电话','mDataProp':'phoneNum'},
                    {'sTitle': '预警类型', 'mDataProp': 'warntype','mRender':function(data, type, full){
                    	if(data=='AllDay'){
                    		return '24小时预警'
                    	}else{
                    		return '非24小时预警'
                    	}
                    }},
                    {'sTitle':'操作','bSortable':false,'mRender':function(data, type, full){
						var html='<div class="dropdown">';
			            html+='<a href="javascript:;" title="" class="btn medium bg-blue" data-toggle="dropdown">';
			            html+='<span class="button-content">';
			            html+='<i class="glyph-icon font-size-11 icon-cog"></i>';
			            html+='<i class="glyph-icon font-size-11 icon-chevron-down"></i>';
			            html+='</span>';
			            html+='</a>';
			            html+='<ul class="dropdown-menu float-right">';
			            html+='<li><a href="javascript:;" id="del_'+full.id+'" class="font-red del" title=""><i class="glyph-icon icon-remove mrg5R"></i>删除</a> </li>';
			            html+='';
			            html+='';
			            html+='';
			            html+='</ul>';
			            html+='</div>';
						return html;
					}},
                ],
                "bServerSide": true,
                "sAjaxSource": "/warning/warningAsAjax",
                "fnServerData": retrieveData,
                "oLanguage": {
                    "sInfoEmpty": "没有数据",
                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                    "sZeroRecords": "没有检索到数据",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前页",
                        "sNext": "后页",
                        "sLast": "尾页"
                    }
                },

                "fnDrawCallback": function () {
	                $(".del").click(function(a) {
						$.messager.confirm("", "是否确认删除？", function() { 
					        location.href="/warning/delete/"+a.delegateTarget.id.substring(4);
					    });
					});
                },

                "bRetrieve": true,
                "aoColumnDefs": [
                    {
                        sDefaultContent: '',
                        aTargets: [ '_all' ]
                    }
                ]

            })
        })
        $(document).on("scroll", ".dataTables_scrollBody", function () {
            $(".dataTables_scrollBody").css({"overflow": "visible", "height": "100%"})
        })
    });
  
    
function showNewWarning(){
        var html = '<div id="dialog" class="hide" title="添加预警">' + $("#dialog-add-presale").html() + '</div>';
        $( html ).dialog({
            resizable:!0,
            minWidth:700,
            minHeight:150,
            modal:!0,
            dialogClass:"modal-dialog",
            closeOnEscape:!0,
            close : function() {
                $( this ).dialog( "destroy" );
            },
            buttons: {
                提交: function() {
                    var valid = $('#dialog form').parsley( 'validate' );
                    if(!valid){
                        return;
                    }
					$('#dialog form').trigger('submit');
                }
            }
        });
 };

</script>